package com.barry;

import com.google.common.collect.Lists;
import lombok.Data;
import lombok.NonNull;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Array;
import java.lang.reflect.Modifier;
import java.util.*;

/**
 * @author wangxuexing
 * @descrption mytest
 * @date 2019/12/3
 */
public class Test {
    public static void main(String[] args) {
    /*    List<Obj> list = Lists.newArrayList();
        Obj o1 = new Obj();
        o1.setA(10);
        o1.setB("10");
        list.add(o1);
        System.out.println(list);
        list.forEach(x->x.setA(20));*/
/*        String aString = "word1:word2:word3";
        StringTokenizer parser = new StringTokenizer(aString, ":", false);
        System.out.println(parser.countTokens());
        while (parser.hasMoreTokens()) {
            System.out.println(parser.nextToken());
        }*/
 /*       try {
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            while (str != null) {
                System.out.print("> prompt ");
                str = in.readLine();
                System.out.print(str+"\n");
            }
        } catch (IOException e) {

        }*/
        int mods = Obj.class.getModifiers();
        if (Modifier.isPublic(mods)) {
            // class is public
            System.out.print("true");
        }

        Class[] intfs = Obj.class.getInterfaces();
        for (int i=0; i<intfs.length; i++) {
            System.out.print(intfs[i]);
        }

        Object[] array = new Object[]{1,2};
        Object newArray = Array.newInstance(
                array.getClass().getComponentType(),
                Array.getLength(array)*2);
        System.arraycopy(array, 0, newArray,
                0, Array.getLength(array));
        System.out.println(((Object[])newArray).length);

        for(Object o : (Object[]) newArray){
            System.out.println(o);
        }
        // Get the value of the third element.
        Object o = Array.get(array, 1);
        // Set the value of the third element.
        Array.set(array, 1, 8);
        for(Object f : array){
            System.out.println(f);
        }

        Obj obj = null;
        isValid(obj);

//        Stringp[] targets = StringUtils.split(source, "::");
/*
        List<Obj> list = null;
        System.out.println(list(list));

        Map<String, String> a = Maps.newHashMap();
        a.put(null, null);*/
    }

    @Data
    private static class Obj{
        private int a;
        private String b;
        public String toString(){
            return a+" "+b;
        }
    }

    public static boolean isValid(@NonNull Obj user) {
        return true;
    }

    private static List<Obj> list(List list){
        List<Obj> myList = Lists.newArrayList();
        if(!CollectionUtils.isEmpty(list)){
            myList.addAll(list);
        }
        Obj o1 = new Obj();
        o1.setA(10);
        o1.setB("10");
        myList.add(o1);
        return myList;
    }
}
